import pandas as pd
from sklearn.ensemble import IsolationForest
from sklearn.preprocessing import StandardScaler

# 加载日志数据
log_data = pd.read_csv('log_data.csv')

# 提取特征
features = log_data[['connection_counts', 'connection_duration', 'has_periodicity']]

# 标准化特征数据
scaler = StandardScaler()
scaled_features = scaler.fit_transform(features)

# 使用孤立森林算法进行异常检测
isolation_forest = IsolationForest()
isolation_forest.fit(scaled_features)

# 获取异常得分
outlier_scores = isolation_forest.decision_function(scaled_features)

# 设置阈值来确定高危节点
threshold = -0.5
high_risk_nodes = log_data[outlier_scores < threshold]

# 输出高危节点
print(high_risk_nodes)